﻿using System;

namespace UniRx.Operators
{
	// Token: 0x0200032D RID: 813
	internal class TimestampObservable<T> : OperatorObservableBase<Timestamped<T>>
	{
		// Token: 0x060010E7 RID: 4327 RVA: 0x0004DF2F File Offset: 0x0004C32F
		public TimestampObservable(IObservable<T> source, IScheduler scheduler) : base(scheduler == Scheduler.CurrentThread || source.IsRequiredSubscribeOnCurrentThread<T>())
		{
			this.source = source;
			this.scheduler = scheduler;
		}

		// Token: 0x060010E8 RID: 4328 RVA: 0x0004DF59 File Offset: 0x0004C359
		protected override IDisposable SubscribeCore(IObserver<Timestamped<T>> observer, IDisposable cancel)
		{
			return this.source.Subscribe(new TimestampObservable<T>.Timestamp(this, observer, cancel));
		}

		// Token: 0x040009F7 RID: 2551
		private readonly IObservable<T> source;

		// Token: 0x040009F8 RID: 2552
		private readonly IScheduler scheduler;

		// Token: 0x0200032E RID: 814
		private class Timestamp : OperatorObserverBase<T, Timestamped<T>>
		{
			// Token: 0x060010E9 RID: 4329 RVA: 0x0004DF6E File Offset: 0x0004C36E
			public Timestamp(TimestampObservable<T> parent, IObserver<Timestamped<T>> observer, IDisposable cancel) : base(observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x060010EA RID: 4330 RVA: 0x0004DF7F File Offset: 0x0004C37F
			public override void OnNext(T value)
			{
				this.observer.OnNext(new Timestamped<T>(value, this.parent.scheduler.Now));
			}

			// Token: 0x060010EB RID: 4331 RVA: 0x0004DFA4 File Offset: 0x0004C3A4
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x060010EC RID: 4332 RVA: 0x0004DFDC File Offset: 0x0004C3DC
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x040009F9 RID: 2553
			private readonly TimestampObservable<T> parent;
		}
	}
}
